package com.qiyu.datasource.config;

import com.qiyu.datasource.enums.DatasourceConfigEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author linhao
 * @Date created in 5:50 下午 2021/1/28
 */
@Component
public class MultiDataSourceConfig implements InitializingBean {

    private static volatile Map<String, DatasourceConfigEnum> dataSourcePackageMap = new ConcurrentHashMap<>();

    public Map<String, DatasourceConfigEnum> getDataSourcePackageMap() {
        return dataSourcePackageMap;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("init bean");
        dataSourcePackageMap.put("com.qiyu.tech.id.builder.dao.db1", DatasourceConfigEnum.TEST_DB_01);
        dataSourcePackageMap.put("com.qiyu.tech.id.builder.dao.db2", DatasourceConfigEnum.TEST_DB_02);
    }
}
